package com.slwish.xty.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.slwish.common.utils.StringUtils;
import com.slwish.xty.R;
import com.slwish.xty.entity.UserCommentListModel;
import com.slwish.xty.widget.RatingBar;
import com.slwish.xty.widget.flowlayout.FlowLayout;
import com.slwish.xty.widget.flowlayout.TagAdapter;
import com.slwish.xty.widget.flowlayout.TagFlowLayout;

import java.util.ArrayList;
import java.util.List;

/**
 * 模块说明：
 *
 * @author 陈浩
 * @date 2017/11/30
 */

public class UserCommentListAdapter extends BaseQuickAdapter<UserCommentListModel, BaseViewHolder> {
    public UserCommentListAdapter(@Nullable List<UserCommentListModel> data) {
        super(R.layout.item_user_comment_list, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, UserCommentListModel item) {
        try {

            helper.setText(R.id.tv_name, item.getNickName());
            helper.setText(R.id.tv_content, item.getContent());
            helper.setText(R.id.tv_time, item.getTime());
            RatingBar ratingBar = helper.getView(R.id.ratingbar);
            ImageView ivHeader = helper.getView(R.id.iv_header);
            final TagFlowLayout mFlowLayout = helper.getView(R.id.flowlayout);
            ratingBar.setStar(Float.valueOf(item.getGrade()));
            List<String> list = new ArrayList<>();
            List<UserCommentListModel.CommLabel> commLabel = item.getCommLabel();
            for (UserCommentListModel.CommLabel model : commLabel) {
                if (!StringUtils.isEmpty(model.getLabelName()))
                    list.add(model.getLabelName());
            }
//            if (list.size()<1)
//                mFlowLayout.setVisibility(View.GONE);
//            else{
//                mFlowLayout.setVisibility(View.VISIBLE);
            mFlowLayout.setAdapter(new TagAdapter<String>(list) {
                @Override
                public View getView(FlowLayout parent, int position, String s) {
                    TextView tv = (TextView) mLayoutInflater.inflate(R.layout.item_comment_text,
                            mFlowLayout, false);
                    tv.setText(s);
                    return tv;
                }
            });
//        }

            RequestOptions requestOptions = RequestOptions.circleCropTransform()
                    .placeholder(R.mipmap.touxiang56)
                    .error(R.mipmap.touxiang56);
            Glide.with(mContext).load(item.getUserPhoto()).apply(requestOptions).into(ivHeader);

        } catch (Exception e) {
        }
    }
}
